package org.grc.app.z_project.z_sample.aspect;

import java.lang.reflect.Method;

import org.grc.app.z_project.z_framework.annotation.Aspect;
import org.grc.app.z_project.z_framework.annotation.Controller;
import org.grc.app.z_project.z_framework.proxy.AspectProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 拦截所有Controller方法
 * 
 * @author grc
 * @date 2016-5-29 16:06:05
 */
@Aspect(Controller.class)
public class ControllerAspect1 extends AspectProxy {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect1.class);
	
	private long begin = 0;
	
	@Override
	public void before(Class<?> clazz, Method method, Object[] params) throws Throwable {
		LOGGER.info("------------------BEGIN----------------------");
		LOGGER.info(String.format("class: %s", clazz.getName()));
		LOGGER.info(String.format("method: %s", method.getName()));
		begin = System.currentTimeMillis();
	}
	
	@Override
	public void after(Class<?> clazz, Method method, Object[] params) throws Throwable {
		double time = (double)(System.currentTimeMillis() - begin)/1000;
		LOGGER.info(String.format("Time elapsed: %s sec", time));
		LOGGER.info("-------------------END-----------------------");
	}
}
